using Headsight.BPMN2WF.BPMN.Schemas;
using Headsight.BPMN2WF.Testing.TestObjCtors;
using Headsight.BPMN2WF.Transformation.Transformers;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Headsight.BPMN2WF.Testing.TestObjCtorsTest
{
    [TestClass]
    public class BPMN2WFTransformations4TestingCtorTest
    {
        private BPMN2WFTransformations4TestingCtor _sut;

        [TestInitialize]
        public void SetUp()
        {
            _sut = new BPMN2WFTransformations4TestingCtor();
        }

        [TestMethod]
        public void Create()
        {
            var actual = _sut.Create();

            Assert.IsNotNull(actual);

            var bpmnFlowNode = new BPMNFlowNodeCtor().WithTFlowElement(new tUserTask()).Create();
            Assert.IsInstanceOfType(actual.Get(bpmnFlowNode), typeof(BPMN2WFTransformation_4TestingAssign));
        }

        [TestMethod]
        public void With_is_chaining()
        {
            Assert.AreSame(_sut, _sut.With(typeof(tUserTask), typeof(BPMN2WFTransformation_4TestingAssign)));
        }

        [TestMethod]
        public void With_Create()
        {
            var bpmnFlowNode_tUserTask = new BPMNFlowNodeCtor().WithTFlowElement(new tUserTask()).Create();
            var bpmnFlowNode_tScriptTask = new BPMNFlowNodeCtor().WithTFlowElement(new tScriptTask()).Create();

            var actual = _sut.With(typeof (tScriptTask), typeof (BPMN2WFTransformationWriteLine)).Create();

            Assert.IsInstanceOfType(actual.Get(bpmnFlowNode_tUserTask), typeof(BPMN2WFTransformation_4TestingAssign));
            Assert.IsInstanceOfType(actual.Get(bpmnFlowNode_tScriptTask), typeof(BPMN2WFTransformationWriteLine));
        }

        [TestMethod]
        public void WithDefault_is_chaining()
        {
            Assert.AreSame(_sut, _sut.WithDefault(typeof(BPMN2WFTransformationWriteLine)));
        }

        [TestMethod]
        public void WithDefault_Create()
        {
            var actual = _sut.WithDefault(typeof (BPMN2WFTransformationWriteLine)).Create();

            var result = actual.Get(new BPMNFlowNodeCtor().WithTFlowElement(new tScriptTask()).Create());

            Assert.IsInstanceOfType(result, typeof(BPMN2WFTransformationWriteLine));
        }

        [TestMethod]
        public void With_BPMNFlowNode_is_chaining()
        {
            Assert.AreSame(_sut, _sut.With(new BPMNFlowNodeCtor().Create(), new BPMN2WFTransformationCtor().Create()));
        }

        [TestMethod]
        public void With_BPMNFlowNode()
        {
            var bpmnFlowNode1 = new BPMNFlowNodeCtor().WithId("1").Create();
            var bpmnFlowNode2 = new BPMNFlowNodeCtor().WithId("2").Create();

            var bpmn2WfTransformation1 = new BPMN2WFTransformationCtor().Create();
            var bpmn2WfTransformation2 = new BPMN2WFTransformationCtor().Create();

            var actual = _sut.With(bpmnFlowNode1, bpmn2WfTransformation1)
                .With(bpmnFlowNode2, bpmn2WfTransformation2).Create();

            Assert.AreSame(bpmn2WfTransformation1, actual.Get(bpmnFlowNode1));
            Assert.AreSame(bpmn2WfTransformation2, actual.Get(bpmnFlowNode2));
        }
    }
}